<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-3.6.0.min.js"></script>
    <link href="../css/login.css" type="text/css" rel="stylesheet">
</head>
<body>
<div th:include="common/inc"></div>
<div class="formDiv" style="width:500px;border: 1px solid #6FA5DB;border-radius: 10px;">
    <input type="hidden" id="resumeId" name="resumeId">
    <h2 class="text-center">职位详情</h2>
    <form id="loginForm">
        <input type="hidden" id="userId" th:value="${position.userId}" name="userId">
        <input type="hidden" id="positionId" th:value="${position.positionId}" name="positionId">
        <div class="dataform">
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">职位信息:</span>
                <input id="description" name="description" type="text" readonly class="inputs" th:value="${position.description}" maxlength="64">
            </div>
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">职位名称:</span>
                <input id="positionName" name="positionName" type="text" readonly class="inputs" th:value="${position.positionName}" maxlength="64">
            </div>
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">职位职能:</span>
                <input id="functions" name="functions" type="text" readonly class="inputs" th:value="${position.functions}" maxlength="64">
            </div>
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">学历要求:</span>
                <input id="degree" name="degree" type="text" readonly class="inputs" th:value="${position.degree}" maxlength="64">
            </div>
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">工作经验:</span>
                <input id="experience" name="experience" type="text" readonly class="inputs" th:value="${position.experience}" maxlength="64">
            </div>
            <div class="input-warp">
                <span class="input-icon iconfont" style="width: 50px;text-align: right;">薪资范围:</span>
                <input id="salary" name="salary" type="text" readonly class="inputs" th:value="${position.salary}" maxlength="64">
            </div>
<!--            <div class="input-warp">-->
<!--                <span class="input-icon iconfont" style="width: 50px;text-align: right;">公司介绍:</span>-->
<!--                <input id="companyShow" name="companyShow" type="text" readonly class="inputs" th:value="${position.companyShow}" maxlength="64">-->
<!--            </div>-->
<!--            <div class="input-warp">-->
<!--                <span class="input-icon iconfont" style="width: 50px;text-align: right;">公司地址:</span>-->
<!--                <input id="companyAddress" name="companyAddress" type="text" readonly class="inputs" th:value="${position.companyAddress}" maxlength="64">-->
<!--            </div>-->
<!--            <div class="input-warp">-->
<!--                <span class="input-icon iconfont" style="width: 50px;text-align: right;">行业类型:</span>-->
<!--                <input id="companyType" name="companyType" type="text" readonly class="inputs" th:value="${position.companyType}" maxlength="64">-->
<!--            </div>-->
<!--            <div class="input-warp">-->
<!--                <span class="input-icon iconfont" style="width: 50px;text-align: right;">公司规模:</span>-->
<!--                <input id="companySize" name="companySize" type="text" readonly class="inputs" th:value="${position.companySize}" maxlength="64">-->
<!--            </div>-->
<!--            <div class="input-warp">-->
<!--                <span class="input-icon iconfont" style="width: 50px;text-align: right;">融资阶段:</span>-->
<!--                <input id="financingPhase" name="financingPhase" type="text" readonly class="inputs" th:value="${position.financingPhase}" maxlength="64">-->
<!--            </div>-->

            <div class="input-warp gap" style="border: 0px;">
                <input id="toMessage" class="btn btn-block lgbtn blue" type="button" value="去沟通" onclick="toMessage1()">
            </div>
            <div class="input-warp gap" style="border: 0px;margin-top: 5px;">
                <input id="addToLike" class="btn btn-block lgbtn blue" type="button" value="收藏" onclick="addToLike1()">
                <input id="updateToLike" class="btn btn-block lgbtn blue" type="button" value="已收藏" onclick="addToLike1()">
            </div>

            <div class="input-warp gap" style="border: 0px;margin-top: 5px;">
                <input id="toDeliver1" class="btn btn-block lgbtn blue" type="button" value="投递" onclick="addDeliver()">
                <input id="toDeliver2" class="btn btn-block lgbtn blue" type="button" value="已投递">
            </div>

        </div>
    </form>
</div>



</body>

<script>

    var positionId = $("#positionId").val();//获取某个input框的值
    var userId = $("#userId").val();

    $(function(){
        getAddToLike(positionId);
        getDeliver1(positionId)
    })

    //查询
    function getAddToLike(positionId){
        $.ajax({
            url:"/pquery/getAddToLike",
            type:"post",
            data:{"positionId":positionId},
            dataType:"json",    <!--设置返回值为json，就可以直接用 . 获取元素值-->
            success:function (data){
                if(data.status == 1){   //
                    $("#addToLike").hide();
                    $("#updateToLike").show();
                }
                if(data.status == 0){   //
                    $("#updateToLike").hide();
                    $("#addToLike").show();
                }
            },error:function (){
                <!--若是没查到数据，即返回值为空，就会走error方法-->
                $("#updateToLike").hide();
                $("#addToLike").show();
            }
        })
    }

    //去沟通
    function toMessage1(){
        location.href="/information/getInformation?positionId="+positionId+"&userId="+userId;
    }


    //收藏
    function addToLike1(){
        $.ajax({
            url:"/pquery/addToLike",
            type:"post",
            data:{"positionId":positionId},
            dataType:"json",
            success:function (data){
                alert("成功")
                getAddToLike(positionId);
            },error:function (){
                alert("成功")
                getAddToLike(positionId);

            }
        })
    }


    //投递
    function addDeliver(){
        $.ajax({
            url:"/information/addDeliver",
            type:"post",
            data:{"positionId":positionId},
            dataType:"json",
            success:function (data){
                alert("成功")
                getDeliver1(positionId);
            },error:function (){
                alert("成功")
                getDeliver1(positionId);
            }
        })
    }

    //查询投递
    function getDeliver1(positionId){
        $.ajax({
            url:"/information/getDeliver",
            type:"post",
            data:{"positionId":positionId},
            dataType:"json",
            success:function (data){
                if(data != null){
                    $("#toDeliver1").hide();
                    $("#toDeliver2").show();
                } else {
                    $("#toDeliver2").hide();
                    $("#toDeliver1").show();
                }

            },error:function (){
                <!--若是没查到数据，即返回值为空，就会走error方法-->
                $("#toDeliver2").hide();
                $("#toDeliver1").show();
            }
        })
    }

</script>

</html>